package com.hlw.hr_man.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hlw.hr_man.Model.AskForLeave;
import com.hlw.hr_man.Model.EmployeeModel;
import com.hlw.hr_man.service.AskForLeaveService;
import com.hlw.hr_man.serviceImpl.AskForLeaveServiceImpl;

/**
 * 
 * @ClassName: EmployeeApplyAflController
 * @Description: 处理员工申请请假操作
 * @author 唐明
 * @date 2016年9月20日 上午9:59:39
 *
 */
public class EmployeeApplyAflController extends HttpServlet{

	/**
	 * @Fields serialVersionUID : TODO(用一句话描述这个变量表示什么)
	 */ 
	private static final long serialVersionUID = 1L;
	
	AskForLeaveService aflService = new AskForLeaveServiceImpl();

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("utf8");
		//得到当前登录用户
		EmployeeModel employee = (EmployeeModel) req.getSession().getAttribute("loginEmployee");
		int e_id = employee.getE_id();
		//获取页面信息
		String startdate = req.getParameter("startdate");
		String enddate = req.getParameter("enddate");
		String reason = req.getParameter("reason");
		AskForLeave afl = new AskForLeave(0, e_id, startdate, enddate, reason, "0", "0");
		//申请操作是否成功
		boolean temp = aflService.addAfl(afl);
		PrintWriter pw = resp.getWriter();
		
		if (temp) {
			//如果申请请假操作成功，则在servletContext中存放已有请假申请的信息，方便通知管理员
			req.getServletContext().setAttribute("msg", 1);
			//操作成功  返回"1"
			pw.write("1");
		} else {
			//操作失败  返回"0"
			pw.write("0");
		}
	}
}
